package com.zidian.teacher.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import com.zidian.teacher.R;
import com.zidian.teacher.activity.EvaluateListActivity;
import com.zidian.teacher.bean.EvaluateOtherListBean;


/**
 * Created by Administrator on 2016/8/24 0024.
 */
public class EvaluateOtherListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context context;
    private List<EvaluateOtherListBean.DataBean> data;


    public EvaluateOtherListAdapter(Context context, List<EvaluateOtherListBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_evaluate_other_list, parent,
                false);
        return new ItemViewHolder(view);
    }


    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof ItemViewHolder) {

            ((ItemViewHolder) holder).otherTeacherName.setText(data.get(position).getTeacherName());
            ((ItemViewHolder) holder).otherTeacherId.setText(data.get(position).getTeacherId());
            Glide.with(context)
                    .load(data.get(position).getTeacherHeadPortrait())
                    .placeholder(R.drawable.teacher)
                    .centerCrop()
                    .into(((ItemViewHolder) holder).otherTeacherImage);


            ((ItemViewHolder) holder).evaluateBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent intent = new Intent();
                    intent.setClass(context, EvaluateListActivity.class);
                    intent.putExtra("byEvaluatePersonId", data.get(position).getTeacherId());
                    context.startActivity(intent);

                }
            });

        }
    }


    static class ItemViewHolder extends RecyclerView.ViewHolder {
        Button evaluateBtn;

        TextView otherTeacherName;
        TextView otherTeacherId;
        ImageView otherTeacherImage;


        public ItemViewHolder(View view) {
            super(view);
            evaluateBtn = (Button) view.findViewById(R.id.evaluate_other_btn);
            otherTeacherId = (TextView) view.findViewById(R.id.other_teacher_id);
            otherTeacherName = (TextView) view.findViewById(R.id.other_teacher_name);
            otherTeacherImage = (ImageView) view.findViewById(R.id.other_teacher_image);

        }
    }


}
